<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui" 
	template="/template/template.xhtml">

  <ui:define name="center">
  	<h1 class="title ui-widget-header ui-corner-all">${msg['admin.list.title']}</h1>
  	<p:panel header="${msg['admin.form.subtitle']}" id="addBook">
  	
  	<p:messages for="editbookform" showSummary="false" showDetail="true"/>
	<h:form id="editbookform"  enctype="multipart/form-data">
		<h:panelGrid columns="2">  
			<h:outputText value="${msg['admin.form.name']}"/>
			<p:inputText id="title" value="#{bookBean.book.title}" required="true" requiredMessage="${msg['admin.error.title']}"/>
				
			<h:outputText value="${msg['admin.form.actualimage']}"/>
			<h:graphicImage id="gi" alt="#{bookBean.book.title}" value="/resources/img/cover#{bookBean.book.id}" width="100" height="115" title="#{bookBean.book.title}" ></h:graphicImage>
				
			<h:outputText value="${msg['admin.form.changeimage']} : "/>
			<p:fileUpload id="image" value="#{bookBean.file}" mode="simple" />
		
			<h:outputText value="${msg['admin.form.date']}*"/>
	        <p:calendar value="#{bookBean.book.date}" id="cal" showButtonPanel="true" required="true" requiredMessage="${msg['admin.error.date']}"/>
	           
	        <h:outputLabel for="spinnerStep" value="${msg['admin.table.price']}*" />  
	        <p:spinner value="#{bookBean.book.price}" id="spinnerStep" stepFactor="0.5" required="true" validator="#{bookBean.validatePrice}"/>
	          
	        <h:outputLabel value="${msg['admin.form.category']}*" />
	        <p:selectOneMenu value="#{bookBean.categoryId}" required="true" requiredMessage="${msg['admin.error.category']}"> 
	         	<f:selectItems value="#{categoryListBean.categories}" var="category" itemLabel="#{category.title}" itemValue="#{category.id}"/> 
	     	</p:selectOneMenu>
	     	   
	       	<h:outputText value="${msg['admin.form.authors']} : " />
	        <ui:repeat value="#{bookBean.book.authors}" var="author">  
           		<h:outputText value="#{author.firstName} #{author.lastName}"/>
				<h:commandLink class="delete-author" action="#{bookBean.deleteBookAuthor(author)}">	  
					<h:outputText style="color:red;padding-left:10px;" value="X" />
				</h:commandLink><br />
	        </ui:repeat>
	        <h:outputText value="${msg['admin.form.addauthors']} : " />
       	     
	        <p:selectManyMenu value="#{bookBean.authorsId}">  
	            <f:selectItems value="#{authorBean.authors}" var="author" itemLabel="#{author.firstName} #{author.lastName}" itemValue="#{author.id}" /> 
	        </p:selectManyMenu>
	        
			<p:commandButton action="#{bookBean.modify}" value="Valider" ajax="false"/>
		</h:panelGrid>
		<h:outputText styleClass="comment" value="${msg['admin.form.required']}" />
	</h:form>
  </p:panel>
  </ui:define>
</ui:composition>